<?php
namespace app\beautiful\model\mall;
use app\common\model\CommonModel;
use app\beautiful\model\member\MemberModel;

class PinTuanGroupModel extends CommonModel{
    protected  $name = 'beautiful_pin_tuan_group';
    protected  $pk   = 'pin_tuan_group_id';

    public function pinTuanGoods()
    {
        return $this->hasOne(PinTuanGoodsModel::class,'pin_tuan_goods_id','pin_tuan_goods_id');
    }

    public function chief()
    {
        return $this->hasOne(MemberModel::class,'member_id','chief_id');
    }

    public function getDjsTimeAttr($value,$data)
    {
        $djs_time=$data['add_time']+86400-time();
        return $djs_time>0 ? $djs_time : 0;
    }

    public function getRemainNumAttr($value,$data)
    {
        $remain_num = $data['group_size']- $data['num'];
        return $remain_num>0 ? $remain_num : 0 ;
    }
}
